package developer.算法.动态规划.杨辉三角;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyongkang
 * @desc:
 * @since 2024/7/3 15:42
 * <br/>
 * <a href="https://leetcode.cn/problems/pascals-triangle/description/?envType=study-plan-v2&envId=top-100-liked">力扣链接</a>
 *                1
 *              1  1
 *             1  2  1
 *            1  3  3
 *
 */
public class Solution_self {
    public static void main(String[] args) {
        List<List<Integer>> generate = generate(20);
        generate.forEach(a->{
            a.forEach(b->{
                System.out.print(" "+b+" ");
            });
            System.out.println("\n");
        });
    }

    public static List<List<Integer>> generate(int numRows) {
        if (numRows <= 0) return new ArrayList<>();
        List<List<Integer>> result = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            List<Integer> line = new ArrayList<>();
            for (int j = 0; j < i+1; j++) {
                if(j==0|j==i){
                    line.add(1);
                    continue;
                }
                line.add(  result.get(i-1).get(j-1)+result.get(i-1).get(j));
            }
            result.add(line);
        }
        return result;
    }


}
